/**
 * @param {string} digits
 * @return {string[]}
 */
var letterCombinations = function (digits) {
    if(!digits.length){
        return [];
    }
    const list = new Map([
        ['2', 'abc'], ['3', 'def'], ['4', 'ghi'], ['5', 'jkl'], ['6', 'mno'], ['7', 'pqrs'], ['8', 'tuv'], ['9', 'wxyz']
    ]);
    let n = digits.length;
    let result = [];
    let str='';
    function backtrack(index){
        if(index==n){
            result.push(str);
            // console.log(result);
            return ;
        }
        else{
            let value=list.get(digits[index]);
            // console.log(value);
            let length=value.length;
            for(let j=0;j<length;j++){
                str += value[j];
                // console.log(str);
                backtrack(index+1);
                str=str.substr(0,str.length-1);
            }
        }
        
    }
    backtrack(0);
    return result;
};
console.log(letterCombinations('2354'))